package controller;


import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import pojo.Moneys;

import service.MoneyService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@Controller
public class MoneyController {

    @Autowired
    @Qualifier("MoneyServiceImpl")
    private MoneyService moneyService;


    @ResponseBody
    @RequestMapping(value = "/allMoney",produces="text/html;charset=utf-8")
    public String allArticle( HttpServletResponse response, HttpServletRequest request) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/json; charset=utf-8");    // 设置response的编码及格式
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Cache-Control","no-cache");
        List<Moneys> list =  moneyService.queryAllBook();
        String resJSON = JSON.toJSONString(list);     // 转换为json
        return resJSON;
    }


}
